package com.hhf.feiojjudgeservice.strategy;


import com.hhf.feiojcommonservice.model.enums.QuestionSubmitLanguageEnum;
import com.hhf.feiojcommonservice.model.dto.JudgeInfo;
import com.hhf.feiojjudgeservice.strategy.impl.DefaultJudgeStrategy;
import com.hhf.feiojjudgeservice.strategy.impl.JavaJudgeStrategy;

/**
 * @Author hhf
 * @Date 2024/10/28
 * @Description 策略的上下文
 */
public class JudgeStrategyContext {

    private JudgeStrategy strategy;

    private String language;

    private JudgeInfo runJudgeInfo;
    private JudgeInfo needJudgeInfo;

    public JudgeStrategyContext(String language, JudgeInfo runJudgeInfo,JudgeInfo needJudgeInfo) {
        this.language = language;
        this.runJudgeInfo = runJudgeInfo;
        this.needJudgeInfo = needJudgeInfo;

        //根据语言选择判题策略
        if (QuestionSubmitLanguageEnum.JAVA.getValue().equals(language)) {
            this.strategy = new JavaJudgeStrategy();
        } else {
            this.strategy = new DefaultJudgeStrategy();
        }
    }

    public JudgeInfo executeStrategy() {
        return strategy.getJudgeInfo(runJudgeInfo,needJudgeInfo);
    }
}
